﻿using System;
using System.Net.Sockets;
using System.Text;

namespace WJ.Infrastructure.Util
{
    public class Console
    {
        private static bool EnableConsole;
        private static UdpClient _udpClient = null;

        static Console()
        {
            if (Convert.ToBoolean(ConfigUtil.GetConfig("EnableConsole")))
            {
                EnableConsole = true;
                _udpClient = new UdpClient();
            }
            else
            {
                EnableConsole = false;
            }
        }

        public static void Write(string message)
        {
            if (EnableConsole)
            {
                byte[] buffer = Encoding.UTF8.GetBytes(message);
                _udpClient?.Send(buffer, buffer.Length, "127.0.0.1", 4001);
            }
        }
    }
}